#ifndef __CXMLSaxParser_H__
#define __CXMLSaxParser_H__

#include <lampe/types.h>
#include <lampe/stream/IReader.h>
#include <lampe/IReferenceCounted.h>
#include <boost/function.hpp>
#include <lampe/xml/IXMLSaxParser.h>

namespace lampe{
namespace xml{
class CXMLSaxParser:public IXMLSaxParser{
public:
	typedef boost::function<void(CXMLSaxParser*)> XmlSaxEvent;
private:
	struct att{
		String name;
		String value;
	};
	LAMPE_VECTOR_VENDOR<att> attribytes;
	String tag_name;
	char last_char;
	bool empty_node;
	int current_element;
	String text;
	bool cdata;
	XmlSaxEvent process;
	void*tagObject;



	void nodeReaded();
	void readComment(stream::IReader*reader);
	void readCDATA(stream::IReader*reader);
	void readSpec(stream::IReader*reader);
	void setNodeType(int type);
	void setAtt(String name,String value);
	void setAtt(String name);
	void readSpace(stream::IReader*reader);
	void readTagName(stream::IReader*reader);
	String readAttributeValue(stream::IReader*reader);
	String readAttributeName(stream::IReader*reader);
	void TagReaded();
public:
	static String nodeTypeToString(int type);

	CXMLSaxParser();

	int getNodeType();
	String getNodeName();
	bool isEmptyElement();
	u32 getAttributeCount();
	String getAttributeName(u32 index);
	String getAttributeValue(u32 index);
	String getNodeData();
	bool isCDATA();

	void read(stream::IReader*reader,XmlSaxEvent process);
	void setTag(void*tagObject);
	void*getTag();
};

}//namespace xml
}//namespace lampe

#endif
